Skip to content

Conversation

@jishnub
Copy link
Member

@jishnub jishnub commented Apr 22, 2025

The advantage of this is that we may forward the indexing to the parent, and if the parent is a structured matrix and the band is a compile-time constant, the value may be evaluated as a constant.

E.g.:

julia> A = UnitUpperTriangular(reshape(1:9, 3, 3))
3×3 UnitUpperTriangular{Int64, Base.ReshapedArray{Int64, 2, UnitRange{Int64}, Tuple{}}}:
 1  4  7
   1  8
     1

julia> function f(A, i, ::Val{band}) where {band}
           x = Adjoint(A)[LinearAlgebra.BandIndex(band,i)]
           Val(x)
       end
f (generic function with 1 method)

julia> @inferred f(A, 1, Val(0))
Val{1}()

julia> @inferred f(A, 1, Val(1))
Val{0}()

In this case, the band index 0 is forwarded to the parent (UnitUpperTriangular), and the getindex is evaluated at compile-time to return 1 (if within bounds). Similarly, the band index 1 corresponds to the zeros of the triangular matrix, so the value is evaluated at compile-time. This may help with removing branches in indexing.

@jishnub jishnub added the performance Must go faster label Apr 22, 2025
@codecov
Copy link

codecov bot commented Apr 24, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 93.75%. Comparing base (e7a8a15) to head (9ac4db5).
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1299      +/-   ##
==========================================
+ Coverage   93.73%   93.75%   +0.02%     
==========================================
  Files          34       34              
  Lines       15682    15689       +7     
==========================================
+ Hits        14699    14710      +11     
+ Misses        983      979       -4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jishnub jishnub force-pushed the jishnub/adjtrans_bandindex branch from 025f191 to 9ac4db5 Compare April 26, 2025 06:16
@jishnub jishnub merged commit bfab205 into master Apr 26, 2025
4 checks passed
@jishnub jishnub deleted the jishnub/adjtrans_bandindex branch April 26, 2025 07:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance Must go faster

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants